package com.example.aop.service;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * ClassName:TransactionAspect
 * Package:com.example.aop.service
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/11-9:20
 * @Version:v1.0
 */
@Component
@Aspect
public class TransactionAspect {

    @Around("execution(* com.example.aop.service..*(..))")
    public void aroundAdvice(ProceedingJoinPoint joinPoint)  {

        try {
            //前环绕
            System.out.println("<===开启事务===>");


            joinPoint.proceed();

            //后环绕
            System.out.println("<===提交事务===>");
        } catch (Throwable e) {
            System.out.println("<===回滚事务===>");
            throw new RuntimeException(e);
        }
    }
}
